<!--
 * new page
 * @author: liuxin
 * @since: 2024-08-18
 * promote.vue
-->
<template>
    <el-dialog v-model="dialogPromoteVisible" title="赋权操作" width="30%" center>
        <el-radio-group v-model="radio" class="ml-4">
            <el-radio label="产品管理员" size="large">产品管理员</el-radio>
            <el-radio label="用户管理员" size="large">用户管理员</el-radio>
            <el-radio label="消息管理员" size="large">消息管理员</el-radio>
        </el-radio-group>
        <template #footer>
            <span class="dialog-footer">
                <el-button>取消</el-button>
                <el-button type="primary" @click="yes">确定</el-button>
            </span>
        </template>
    </el-dialog>


</template>

<script setup lang="ts">
import { ref, reactive } from "vue"
import { bus } from "@/utils/mitt.js"
import { changeIdentityToAdmin } from '@/api/userinfor.js'
import { ElMessage } from 'element-plus'

const userId = ref()
bus.on('promoteId', (id: number) => {
    userId.value = id
})

const radio = ref()

const yes = async () => {
    const res = await changeIdentityToAdmin(userId.value, radio.value)
    if (res.status == 0) {
        ElMessage({
            message: '赋权成功',
            type: 'success'
        })
        bus.emit('offDialog', 1)
        dialogPromoteVisible.value = false
    } else {
        ElMessage.error('赋权失败')
    }
}
// 弹窗开关
const dialogPromoteVisible = ref(false)
// 打开编辑管理员弹窗
const open = () => {
    dialogPromoteVisible.value = true
}
defineExpose({
    open
})
</script>

<style scoped lang="scss">
.el-radio-group {
    display: flex;
    justify-content: center;
}
</style>
